﻿using System.Net;
using __ts.Core.Api;

/*
 *  author: able
 *  @2012/2/21 15:26:28
 * 
 */
namespace __ts.Core.Service
{
    /// <summary>
    /// 
    /// </summary>
    public interface SelectorStrategy
    {
        /**
         * Provide a {@link SelectorProcessor} for a newly accepted {@link IoSession}.
         * @param acceptingProcessor the selector which accepted the {@link IoSession}
         * @return a processor for processing the new session
         */
        SelectorProcessor getSelectorForNewSession(SelectorProcessor acceptingProcessor);

        /**
         * Provide a {@link SelectorProcessor} for a {@link IoSession} which need to write data.
         * This processor will be in charge of selecting the socket for write ready events.
         * 
         * @param session the session in need of writing
         * @return the selector processor for handling this session write events
         */
        SelectorProcessor getSelectorForWrite(IoSession session);

        /**
         * Provide a {@link SelectorProcessor} for processing a newly bound address.
         * The processor will accept the incoming connections.
         * @return a {@link SelectorProcessor} for processing a newly bound address
         */
        SelectorProcessor getSelectorForBindNewAddress();

        /**
         * Unbind an address and remove it from its {@link SelectorProcessor} 
         * @param address the address to be unbound and removed
         * @throws IOException thrown if any problem occurs while unbinding
         */
        void unbind(SocketAddress address);
    }
}